<?php
/**
 * View
 * 
 * 作者:  姚刚 (yaogang@the9sense.com)
 * 创建时间: 2011-02-24 00:16:44
 * 修改记录: 
 * 
 * $Id: View.php 18 2011-04-17 12:50:07Z coosuu $
 */

class View {

    private static $_instance = null;

    public function __construct() {

        $this->smarty = new Smarty;

        $this->smarty->template_dir = APP_PATH . '/templates';
        $this->smarty->compile_dir = APP_PATH . '/tmp/template_c';
        $this->smarty->plugins_dir[] = dirname(__FILE__) . '/View/Smarty/plugins';

    }

    public function &getInstance() {

        if (!self::$_instance) {
            self::$_instance = new self;
        }
        return self::$_instance;
    }

    public function set($key, $value = null) {

        $this->smarty->assign($key, $value);
    }

    public function render($tpl, $return = false) {

        $this->set('controllerName', Bootstrap::getEnv('controllerName'));
        $this->set('actionName', Bootstrap::getEnv('actionName'));
        $this->set('SERVER', $_SERVER);

        $this->set('Lang', Language::get());

        $tpl .= '.tpl';

        if ($return) {
            return $this->smarty->fetch($tpl);
        }

        return $this->smarty->display($tpl);
    }
}
